#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
#define rep(i,l,r) for(int i=(l),i##end=(r);i<=i##end;++i)
#define per(i,r,l) for(int i=(r),i##end=(l);i>=i##end;--i)
#define int long long
#define double long double
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define rbtree(way) tree<way,null_type,less<way>,rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
const int maxn=1e5+10,maxm=1e6+10,mod=998244353,inf=1e18;
inline int ksm(int x,int k,int mod=mod){
	int ans=1;
	for(;k;k>>=1,x=x*x%mod) if(k&1) ans=ans*x%mod;
	return ans;
}

int n,m,q,ans,c[maxn],qr[8],tmp[8],s[maxn<<2][8][8];
//int aqr[8][8],atmp[8][8],a[maxn][8][8];
void build(int id,int l,int r){
	if(l==r){
//		cerr<<l<<"]";
		rep(x,0,m) rep(y,0,m) s[id][x][y]=-inf;
		rep(j,1,m) cin>>s[id][j][j];
		s[id][0][0]=s[id][0][c[l]]=s[id][c[l]][0]=s[id][c[l]][c[l]];
//		rep(x,0,m) rep(y,0,m) a[l][x][y]=s[id][x][y];
		return;
	}
	build(id<<1,l,l+r>>1),build(id<<1|1,(l+r>>1)+1,r);
	rep(x,0,m) rep(y,0,m) s[id][x][y]=-inf;
	rep(x,0,m) rep(y,0,m) rep(z,0,m) s[id][x][y]=max(s[id][x][y],s[id<<1][x][z]+s[id<<1|1][z][y]);
}
void query(int id,int l,int r,int lq,int rq){
	if(lq<=l&&r<=rq){
		rep(y,0,m) tmp[y]=qr[y],qr[y]=-inf;
		rep(y,0,m) rep(z,0,m) qr[y]=max(qr[y],tmp[z]+s[id][z][y]);
		return;
	}
	int mid=l+r>>1;
	if(lq<=mid) query(id<<1,l,mid,lq,rq);
	if(mid<rq) query(id<<1|1,mid+1,r,lq,rq);
}
void change(int id,int l,int r,int x,int y){
	if(l==r){
		s[id][0][0]=s[id][0][c[l]]=s[id][c[l]][0]=-inf,c[l]=y,
		s[id][0][0]=s[id][0][c[l]]=s[id][c[l]][0]=s[id][c[l]][c[l]];
//		rep(x,0,m) rep(y,0,m) a[l][x][y]=s[id][x][y];
		return;
	}
	int mid=l+r>>1;
	if(x<=mid) change(id<<1,l,mid,x,y);
	else change(id<<1|1,mid+1,r,x,y);
	rep(x,0,m) rep(y,0,m) s[id][x][y]=-inf;
	rep(x,0,m) rep(y,0,m) rep(z,0,m) s[id][x][y]=max(s[id][x][y],s[id<<1][x][z]+s[id<<1|1][z][y]);
}

signed main(){
	freopen("paint.in","r",stdin),freopen("paint.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>m>>q;
	rep(i,1,n) cin>>c[i];
	rep(i,1,m) qr[i]=-inf;
	qr[0]=0,build(1,1,n),query(1,1,n,1,n),cout<<(ans=qr[0])<<'\n';
	rep(o,1,q){
		int opt,x,y;
		cin>>opt>>x>>y,x^=ans,y^=ans;
		if(opt==1) change(1,1,n,x,y);
		else{
//			rep(i,0,m) rep(j,0,m) aqr[i][j]=i==j?0:-inf;
//			rep(i,x,y){
//				rep(x,0,m) rep(y,0,m) atmp[x][y]=aqr[x][y],aqr[x][y]=-inf;
//				rep(x,0,m) rep(y,0,m) rep(z,0,m) aqr[x][y]=max(aqr[x][y],atmp[x][z]+a[i][z][y]);
//			}
//			cout<<x<<","<<y<<":"<<aqr[0][0]<<":";
			rep(i,1,m) qr[i]=-inf;
			qr[0]=0,query(1,1,n,x,y),cout<<(ans=qr[0])<<'\n';
		}
	}
	return 0;
}
